package org.cnc.explain.lifecycle.beaninstance_6;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.SmartInstantiationAwareBeanPostProcessor;

import java.lang.reflect.Constructor;

/**
 * <p>
 * #TODO: desc
 * </p>
 *
 * @author zhiyong.tan
 * @since 2022-08-28
 */
public class MySmartInstantiationAwareBeanPostProcessor implements SmartInstantiationAwareBeanPostProcessor {

	@Override
	public Constructor<?>[] determineCandidateConstructors(Class<?> beanClass, String beanName) throws BeansException {
		if(BeanInstanceBean.class.equals(beanClass)){
			Constructor<?>[] constructors = beanClass.getDeclaredConstructors();
			for(Constructor<?> c:constructors){
				if(c.getParameterTypes().length !=0){
					return new Constructor[]{c};
				}
			}
		}
		return SmartInstantiationAwareBeanPostProcessor.super.determineCandidateConstructors(beanClass, beanName);
	}
}
